/**
 * file
 */
package com.tdkj.action.front.member.seller.sell;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.opensymphony.xwork2.ActionContext;
import com.tdkj.action.BaseAction;
import com.tdkj.model.shop.BeanEvaluate;
import com.tdkj.model.shop.BeanEvaluateType;
import com.tdkj.model.shop.BeanOrderItem;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.shop.IBeanEvaluateTypeService;
import com.tdkj.service.shop.IBeanGoodService;
import com.tdkj.util.PublicConfing;

public class EvaluateAction extends BaseAction {
	
	private Long orderItemId;
	
	private Long typeId;
	
	private String content;

	private List<BeanEvaluateType> types;
	
	private IBeanGoodService goodService;
	
	private IBeanEvaluateTypeService evaluateTypeService;
	
	private BeanOrderItem item;
	
	public String execute(){
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		
		goodService.isSellerEvaluated(orderItemId);
		
		types = evaluateTypeService.findAll(BeanEvaluateType.class);
		
		return "success";
	}
	
	
	public String evaluate(){
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		Long userId = user.getId();
		
		if(goodService.isSellerEvaluated(orderItemId)){
			return "";
		}
		
		goodService.addEvaluateOfSeller(orderItemId, userId, typeId, content);
		
		return view();
	}
	
	public String view(){
		
		item =  goodService.findById(orderItemId, BeanOrderItem.class);
		
		String hql = " select bean.sellerEvaluate from " + BeanOrderItem.class.getName() + " as bean where bean.id = '"+orderItemId+"' ";
		Query query = this.getBaseService().getBaseDao().getSession().createQuery(hql);
		
		BeanEvaluate evaluate = (BeanEvaluate)query.uniqueResult();
		this.getReturnInfo().put("evaluate", evaluate);
		
		return "view";
	}

	public Long getOrderItemId() {
		return orderItemId;
	}

	public void setOrderItemId(Long orderItemId) {
		this.orderItemId = orderItemId;
	}

	public Long getTypeId() {
		return typeId;
	}

	public void setTypeId(Long typeId) {
		this.typeId = typeId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public List<BeanEvaluateType> getTypes() {
		return types;
	}

	public void setTypes(List<BeanEvaluateType> types) {
		this.types = types;
	}

	@Resource
	public void setEvaluateTypeService(IBeanEvaluateTypeService evaluateTypeService) {
		this.evaluateTypeService = evaluateTypeService;
	}

	public BeanOrderItem getItem() {
		return item;
	}


	public void setItem(BeanOrderItem item) {
		this.item = item;
	}

	@Resource
	public void setGoodService(IBeanGoodService goodService) {
		this.goodService = goodService;
	}

	
}
